<?php
date_default_timezone_set('PRC');
session_start();
if (isset($_SESSION['openid']) && isset($_POST['p'])){
    $_SESSION['code']=rand(1001,9999);
    
    //echo json_encode(array('s'=>'y','c'=>$_SESSION['code'])); //test
   // exit;//test
    
    include '../c/config.php';
    define("YM_SMS_ADDR",   "www.btom.cn:8080");
    define("YM_SMS_SEND_URI",  "/simpleinter/sendSMS");
    define("YM_SMS_APPID", $smsAppid);
    define("YM_SMS_AESPWD", $smsPd);
    define("END",  "\n");
    function http_request($url, $data)
    {
        $data = http_build_query($data);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_POST, TRUE);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }
    function signmd5($appId,$secretKey,$timestamp){
        return md5($appId.$secretKey.$timestamp);
    }
    $content = "【谦玛】验证码".$_SESSION['code']."，您正在登录小游戏，若非本人操作，请勿泄露。";/* 短信内容请以商务约定的为准，如果已经在通道端绑定了签名，则无需在这里添加签名 */
    $timestamp = date("YmdHis");
    $sign = signmd5(YM_SMS_APPID,YM_SMS_AESPWD,$timestamp);
    $data = array(
        "appId" => YM_SMS_APPID,
        "timestamp" => $timestamp,
        "sign" => $sign,
        "mobiles" => $_POST['p'],
        "content" =>  $content
    );
    $url = YM_SMS_ADDR.YM_SMS_SEND_URI;
    $resobj = http_request($url, $data);
    $theData=json_decode($resobj, true);
    if(isset($theData['code']) && 'SUCCESS' == $theData['code']){
        echo json_encode(array('s'=>'y'));
    }
}
?>
